package com.cdu.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * projectName : easy-help-v2
 * className: ApiDocConfig
 * description: TODO 类描述
 *
 * @author : chengjiang@asiainfo.com
 * @date: 2022/05/10
 */

@Configuration
@EnableOpenApi
@EnableKnife4j
@ConfigurationProperties(prefix = "com.cdu")
@Slf4j
@Getter
@Setter
public class ApiDocConfig {
    private String name;
    private String url;
    private String email;

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        log.info("name: {}, url: {}, email: {}", name, url, email);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("easy-help-v2: api-docs")
                        .description("help you every time")
                        .termsOfServiceUrl("https://jasonch.tech/easy-help/v2/")
                        .contact(new Contact(
                                name,
                                url,
                                email
                        ))
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("easy-help-api")
                .select()
                //这里指定Controller扫描包路径
                // .apis(RequestHandlerSelectors.basePackage("com.github.xiaoymin.knife4j.controller"))
                .paths(PathSelectors.any())
                .build();
    }
}
